package com.theyeasy.dvmini.pc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.theyeasy.dvmini.model.Autoreply;
import com.theyeasy.dvmini.pc.controller.BaseController;
import com.theyeasy.dvmini.service.AutoreplyService;
import com.theyeasy.dvmini.vo.Vo_msg;
 

@Controller
@RequestMapping("/autoreply")
public class AutoreplyController extends BaseController{
	
    @Autowired
    AutoreplyService replyService;
    
    @RequestMapping("/autoresponse")
    public ModelAndView autoreplyIndex(){
        ModelAndView mv = new ModelAndView("/pc/autoresponse/autoresponse");
        return mv;
    }
    
    
    @RequestMapping("/autoresponseEdit")
    public ModelAndView autoresponseEdit(Integer id){
        ModelAndView mv = new ModelAndView("/pc/autoresponse/autoresponseEdit");
        mv.addObject("id", id);
        System.out.println("id"+id);
        return mv;
    }
    //自动回复列表
    @RequestMapping(value = "/getAutoreplyList")
    @ResponseBody
    public Object autoreplyList(Integer page,String keyword,Boolean isRedirectStaff) {
        
        return new Vo_msg(0,replyService.getAutoReplyList(page, keyword,isRedirectStaff));
    }
    
    //添加关键字
    @RequestMapping(value = "/addAutoreply")
    @ResponseBody
    public Object addautoreply(String keywords,boolean isRedirectStaff,String content) {
        String result=replyService.addAutoReply(keywords, isRedirectStaff, content);
        if(result.equals("ok")){
            return new Vo_msg(0,"添加成功");
        }else{
            return new Vo_msg(-1,result);
        }
    }
    
    //修改关键字
    @RequestMapping(value = "/updateAutoreply")
    @ResponseBody
    public Object updateautoreply(Integer id,String keywords,boolean isRedirectStaff,String content) {
        String result=replyService.updateAutoReply(id, keywords, isRedirectStaff, content);
        if(result.equals("ok")){
            return new Vo_msg(0,"修改成功");
        }else{
            return new Vo_msg(-1,result);
        }
    }
    
    //删除关键字
    @RequestMapping(value = "/deleteAutoreply")
    @ResponseBody
    public Object deleteautoreply(Integer id) {
        String result=replyService.deleteAutoReply(id);
        if(result.equals("ok")){
            return new Vo_msg(0,"删除成功");
        }else{
            return new Vo_msg(-1,result);
        }
    }
    
    //获取
    @RequestMapping(value = "/getAutoReply")
    @ResponseBody
    public Object getAutoReply(Integer id) {
        Autoreply reply=replyService.getAutoReply(id);
        if(reply!=null){
            return new Vo_msg(0,reply);
        }else{
            return new Vo_msg(-1,"获取失败，数据为空");
        }
    }
}